package g

import (
	"sync"
)

// https://github.com/URLooker/web/blob/c7d11a269fe913496b98fda1b4444df70b2e5b6a/g/var.go

var (
	DetectedItemMap = &DetectedItemSafeMap{M: make(map[string][]*DetectedItem)}
)

type IpIdc struct {
	Ip  string
	Idc string
}

//下发给agent的数据结构
type DetectedItem struct {
	Sid        int64  `json:"Sid"`
	Domain     string `json:"Domain"`
	Target     string `json:"Target"`
	Ip         string `json:"Ip"`
	KeyWords   string `json:"KeyWords"`
	TimeOut    int    `json:"TimeOut"`
	Creator    string `json:"Creator"`
	Data       string `json:"Data"`
	Tag        string `json:"Tag"`
	ExpectCode string `json:"ExpectCode"`
	Idc        string `json:"Idc"`
}

//agent上报的数据结构
type CheckResult struct {
	Sid      int64  `json:"Sid"`
	Domain   string `json:"Domain"`
	Target   string `json:"Target"`
	Creator  string `json:"Creator"`
	Tag      string `json:"Tag"`
	RespCode string `json:"RespCode"`
	RespTime int    `json:"RespTime"`
	Status   int64  `json:"Status"`
	PushTime int64  `json:"PushTime"`
	Ip       string `json:"Ip"`
}

type DetectedItemSafeMap struct {
	sync.RWMutex
	M map[string][]*DetectedItem
}

func (this *DetectedItemSafeMap) Get(key string) ([]*DetectedItem, bool) {
	this.RLock()
	defer this.RUnlock()
	ipItem, exists := this.M[key]
	return ipItem, exists
}

func (this *DetectedItemSafeMap) Set(detectedItemMap map[string][]*DetectedItem) {
	this.Lock()
	defer this.Unlock()
	this.M = detectedItemMap
}
